package 路径转换注解;

import com.sun.javafx.logging.PulseLogger;

import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/14 20:22
 * @Description:
 */
public class PathTest {
    @Path
    public static String path = "127.0.0.1";
    //    @Path
//    public String age="23";
    public static String name = "111";

    public String getPath() {
        return path;
    }

    public static void main(String[] args) throws IllegalAccessException {
        PathTest pathTest = new PathTest();
        Class c = pathTest.getClass();
        for (Field declaredField : PathTest.class.getDeclaredFields()) {
            //判断static
            if (Modifier.isStatic(declaredField.getModifiers()))
            {       //判断类型
                if (String.class.equals(declaredField.getType())) {
                    declaredField.set(null, "aaa");

                    declaredField.set(null, 20);
                } else if (int.class.equals(declaredField.getType())) {
                    declaredField.set(null, 20);
                } else declaredField.set(null, null);
            }
        }

        for (Field declaredField : c.getDeclaredFields()) {
            boolean annotationPresent = declaredField.isAnnotationPresent(Path.class);
            if (annotationPresent) {
                declaredField.set(null, "aaa");
            }
//            declaredField.set(PathTest.class,"ccc");
        }
        System.out.println(pathTest.getPath());
//        System.out.println(pathTest.age);
        System.out.println(PathTest.path);
        System.out.println(PathTest.name);
    }
}
